package server.valves;

import server.Contained;
import server.Container;
import server.Valve;
import server.ValveContext;
import server.connector.http.HttpRequestImpl;
import server.connector.http.HttpResponseImpl;

import javax.servlet.ServletException;
import java.io.IOException;

public class ClientIPLoggerValve implements Valve, Contained {
    protected Container container;
    @Override
    public Container getContainer() {
        return container;
    }

    @Override
    public void setContainer(Container container) {
        this.container = container;
    }

    @Override
    public String getInfo() {
        return null;
    }

    @Override
    public void invoke(HttpRequestImpl request, HttpResponseImpl response, ValveContext context) throws IOException, ServletException {
        context.invokeNext(request, response);
        System.out.println("Client IP Logger Valve");
        System.out.println(request.getRemoteAddr());
        System.out.println("------------------------------------");
    }
}
